<script setup lang="ts">
import type { CheckboxValueType } from 'ant-design-vue/es/checkbox/interface';

import { computed } from 'vue';

import { ApiComponent } from '@vben/common-ui';

import { CheckboxGroup } from 'ant-design-vue';

import { createApiFunction } from '#/util/tool';

const props = defineProps<{
  api: ((arg?: any) => Promise<any[] | Record<string, any>>) | string;
  // 请求方式
  requestMethod?: 'get' | 'post';
  value?: Array<CheckboxValueType>;
}>();

const emit = defineEmits<{
  (e: 'update:value', value: Array<CheckboxValueType> | undefined): void;
}>();

const value = computed({
  get() {
    return props.value;
  },
  set(val) {
    emit('update:value', val);
  },
});
defineExpose({
  getValue() {
    return value.value;
  },
});
</script>
<template>
  <ApiComponent
    :api="createApiFunction(api, requestMethod)"
    v-model="value"
    model-prop-name="value"
    :component="CheckboxGroup"
  />
</template>
<style lang="less" scoped></style>
